import { createRouter, createWebHistory } from 'vue-router'
import common from './statisModules'


const routes = [
  {
    path: '',
    name: 'index',
    // redirect: '/index',
    component: () => import('@/views/Layout/index.vue'),
    meta: {title: '首页'},
    children: [
      ...common
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/index.vue'),
    meta: {title: '登录页'}
  },
  {
    // 捕获所有路由或 404 Not found路由
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]
const router = createRouter({
  history: createWebHistory(),
  routes,
})

// 全局前置守卫
/*
to 即将要进入的路由信息
form 当前导航正要离开的路由
return false 取消当前导航
next 

*/
// router.beforeEach((to, from, next) => {
//   console.log(to, '?1')
//   // 返回false取消导航
//   // return false
//   next()
// })

// // 是获取数据或执行任何其他操作的位置
// router.beforeResolve((to, from, next) => {
//   console.log(to, '?2')
//   next()
// })

router.beforeEach((to, from, next) => {
  next()
})
export default router
